package com.zjitc.common.handler;

import com.zjitc.common.exception.AuthException;
import com.zjitc.common.utils.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: ${赵诚挚}
 * @Date: 2024/6/21 10:57
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /*运行时异常拦截*/
    @ExceptionHandler(RuntimeException.class)
    public RespBean handlerRuntimeException(Exception e) {
        return RespBean.error(201, "运行时异常：" + e.getMessage());
    }

    /*自定义异常拦截*/
    @ExceptionHandler(AuthException.class)
    public RespBean handlerAuthException(Exception e) {
        return RespBean.error(202, "自定义异常：" + e.getMessage());
    }
}